import { Component } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { createFormGroup } from '../utils';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styles: [],
})
export class HomeComponent {

  myForm: any;

  constructor(
      private fb: FormBuilder,
  ) {
    this.myForm = this.fb.group({});
  }

  submit() {
    console.log('-----------');
    console.log('submit value', this.myForm.getRawValue());
    console.log('-----------');
  }

  initial() {
    let initData = {
      a: 111,
      b: {
        time: [{aaa: 'bbb', ccc: 'ddd'}],
      },
      c: [
        {
          aaa: 222,
          bbb: {444: 555},
        },
      ],
      ddd: 9994,
      eee: {aaa: 123},
    };
    console.log('-----------');
    console.log('form result before', this.myForm.controls);
    this.myForm = createFormGroup(initData);
    console.log('form result after', this.myForm.controls);
    console.log('-----------');
  }
}
